//
//  TestPopAnimationViewController.m
//  LottieAnimationTest
//
//  Created by Felix Yin on 2019/4/10.
//  Copyright © 2019 Felix Yin. All rights reserved.
//

#import "TestPopAnimationViewController.h"
#import "POP.h"

@interface TestPopAnimationViewController ()

@property(nonatomic,strong) UIView *oneView;
@property(nonatomic,strong) UIView *twoView;
@property(nonatomic,strong) POPBasicAnimation *animation;

@end

@implementation TestPopAnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.oneView];
    [self.view addSubview:self.twoView];
    [self popAnimationAndSystemAnimationTest];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//    self.animation.tracer = !self.animation.paused;
}

- (void) popAnimationAndSystemAnimationTest{
    POPBasicAnimation *oneAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPosition];
    oneAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(self .view.center.x+60,125)];
    oneAnimation.duration = 1;
    oneAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    oneAnimation.repeatForever = YES;
//    oneAnimation.autoreverses = YES;
    oneAnimation.paused = YES;
    self.animation = oneAnimation;
    [self.oneView.layer pop_addAnimation:oneAnimation forKey:@"POPBasicAnimation"];
    
    CABasicAnimation *twoAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    twoAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(self
                                                                 .view.center.x+60,195)];
    twoAnimation.duration = 1;
    twoAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    twoAnimation.repeatCount = MAXFLOAT;
    [self.twoView.layer addAnimation:twoAnimation forKey:@"CABasicAnimation"];
}

//    MARK: Lazy Loading

- (UIView *)oneView{
    if (!_oneView) {
        _oneView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 150, 50)];
        _oneView.backgroundColor = [UIColor blueColor];
    }
    return _oneView;
}

- (UIView *)twoView{
    if (!_twoView) {
        _twoView = [[UIView alloc] initWithFrame:CGRectMake(10, 170, 150, 50)];
        _twoView.backgroundColor = [UIColor redColor];
    }
    return _twoView;
}

@end
